package com.fz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by webrx on 2017-09-02.
 */
@Controller
public class Hello {
    @RequestMapping("/test") @ResponseBody
    public void test(){
        System.out.println("hello springmvc");
    }

    @RequestMapping("/user.action") @ResponseBody
    public void user(HttpServletResponse resp) throws IOException {
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();
        out.print("hello中国人");
        out.flush();
        out.close();
    }

    @RequestMapping("/info")
    public ModelAndView info(ModelAndView mv){
        mv.setViewName("info");
        mv.addObject("name","张三丰");
        mv.addObject("address","河南省郑州市文化路28号");
        return mv;
    }

    @RequestMapping("")  //默认
    //@RequestMapping(value = "/index.action")
    public String show(Model m){
        m.addAttribute("name","李四四");
        return "ok"; //
    }
}
